package com.hxgis.statisticanalysis.intelligentIndicator.dao.jpa;

import com.hxgis.statisticanalysis.intelligentIndicator.pojo.MonthReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author 赵恒
 * @date 2023/1/4
 */
public interface MonthReportJpa extends JpaRepository<MonthReport, Integer> {

    List<MonthReport> findMonthReportByMonthAndTitle(String month, String title);

    @Query(value = "select * from `month_report` where month = :month and name = :name", nativeQuery = true)
    List<MonthReport> query(@Param("month") String month, @Param("name") String name);

    @Query(value = "select count(*) from `month_report` where month = :month and name = :name", nativeQuery = true)
    int findByMonthAndName(@Param("month") String month, @Param("name") String name);

    @Transactional
    @Modifying
    @Query(value = "update `month_report` set content = :content where month = :month and name = :name ", nativeQuery = true)
    int updateByMonthAndName(String month, String name, String content);
}
